package tul.cot.job.output;

import java.io.File;
import java.io.IOException;
import java.util.Comparator;

import org.apache.hadoop.conf.Configuration;

public abstract class OutputGetter {
	
//	public static OutputGetter create(boolean fsLocal) {
//		if (fsLocal)
//			return new LocalGetter();
//		
//		return new HDFSGetter();
//	}
	
	public static OutputGetter create(Configuration conf) {
		return new FSGetter(conf);
	}

	public OutputGetter(Configuration conf) {
		this.conf = conf;
	}
	
	private Configuration conf;
	private File fromDir;
	private File toDir;
	private Comparator<String> labelCmp;
	private LineSaver saver;
	
	public void init(File fromDir, File toDir,
			Comparator<String> labelCmp, LineSaver saver) {
		this.fromDir = fromDir;
		this.toDir = toDir;
		this.labelCmp = labelCmp;
		this.saver = saver;
	}
	
	protected Configuration getConf() {
		return conf;
	}
	
	protected File getFromDir() {
		return fromDir;
	}
	
	protected File getToDir() {
		return toDir;
	}
	
	protected Comparator<String> getLabelComparator() {
		return labelCmp;
	}
	
	protected abstract Iterable<String> getLines() throws IOException;

	public void getOutput() throws IOException {
		Iterable<String> lines = getLines();
		saver.saveLines(lines, toDir);
	}
	
}
